<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css">
  <script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yimig.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="一个小时钟看似功能简单，但却使用了多窗口、侧边栏停靠、timer触发等等重要的图形化应用知识。下面将对每一个知识进行单独总结，方便日后学习。">
<meta property="og:type" content="article">
<meta property="og:title" content="【C#】“小时钟”知识点总结">
<meta property="og:url" content="http://yimig.github.io/2018/08/18/csharp_miniclock_summary/index.html">
<meta property="og:site_name" content="Tim&#39;s Blog">
<meta property="og:description" content="一个小时钟看似功能简单，但却使用了多窗口、侧边栏停靠、timer触发等等重要的图形化应用知识。下面将对每一个知识进行单独总结，方便日后学习。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-18_09-31-55.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-19_12-26-35.png">
<meta property="article:published_time" content="2018-08-18T01:43:17.000Z">
<meta property="article:modified_time" content="2020-10-28T14:47:16.070Z">
<meta property="article:author" content="Tim">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-18_09-31-55.png">

<link rel="canonical" href="http://yimig.github.io/2018/08/18/csharp_miniclock_summary/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>【C#】“小时钟”知识点总结 | Tim's Blog</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64126ab668fa908027cba9464a0afec7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Tim's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Learn Everything!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/schedule/" rel="section"><i class="fa fa-fw fa-calendar"></i>日程表</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/yimig" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yimig.github.io/2018/08/18/csharp_miniclock_summary/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/uploads/avatar.png">
      <meta itemprop="name" content="Tim">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tim's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【C#】“小时钟”知识点总结
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-08-18 09:43:17" itemprop="dateCreated datePublished" datetime="2018-08-18T09:43:17+08:00">2018-08-18</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-10-28 22:47:16" itemprop="dateModified" datetime="2020-10-28T22:47:16+08:00">2020-10-28</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Coding/" itemprop="url" rel="index"><span itemprop="name">Coding</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Coding/Csharp/" itemprop="url" rel="index"><span itemprop="name">Csharp</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Coding/Csharp/Common/" itemprop="url" rel="index"><span itemprop="name">Common</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
              <span>5.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>一个小时钟看似功能简单，但却使用了多窗口、侧边栏停靠、timer触发等等重要的图形化应用知识。下面将对每一个知识进行单独总结，方便日后学习。<br><a id="more"></a></p>
<h1 id="窗口类"><a href="#窗口类" class="headerlink" title="窗口类"></a>窗口类</h1><h2 id="①创建和控制多窗口"><a href="#①创建和控制多窗口" class="headerlink" title="①创建和控制多窗口"></a><strong>①创建和控制多窗口</strong></h2><p>创建多窗口：在项目名上右键，添加，windows窗口。<img src="http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-18_09-31-55.png" alt=""> 控制多窗体： 首先，用新创建的窗体类（窗体名即类名）实例化一个窗体对象 在某个控件被触发时，使用方法<strong>Show.对象名()</strong>弹出目标窗口（ShowDialog.对象名()可以在弹出新窗体后禁用原窗体（无法操作化）） 如，想让窗体Form1在一开始便弹出窗体clock1，可用以下语句</p>
<figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">partial</span> <span class="keyword">class</span> <span class="title">Form1</span> : <span class="title">Form</span></span><br><span class="line">&#123;</span><br><span class="line">    clock clock1 = <span class="keyword">new</span> clock();</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">Form1</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>    &#123;</span><br><span class="line">        InitializeComponent();</span><br><span class="line">        clock1.Show ();<span class="comment">//窗口Form1一载入即载入窗口clock1</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="②更改窗口参量"><a href="#②更改窗口参量" class="headerlink" title="②更改窗口参量"></a><strong>②更改窗口参量</strong></h2><p>Ⅰ.更改窗口参量时，对于多窗口使用窗口<strong>方法名.参量</strong>，没有就先实例化，对于本窗口自身<strong>直接用This.参量</strong>。 Ⅱ.有的参量是变量，比如布尔型的True、False可以直接赋值，但是如果提示不是变量就需要用new实例化进行“赋值”。 Ⅲ.如果参量不是静态的，比如时间，要将此传输进This.Text，但是This.Text只支持静态参量，就可以利用Timer控件，在控件中创建一个静态变量，并且此静态变量每秒刷新一次，将此静态变量赋给This.Text即可。</p>
<h4 id="“抹除”窗口背景："><a href="#“抹除”窗口背景：" class="headerlink" title="“抹除”窗口背景："></a>“抹除”窗口背景：</h4><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.BackColor = System.Drawing.Color.Black;<span class="comment">//随便传送一个颜色</span></span><br><span class="line"><span class="keyword">this</span>.TransparencyKey = System.Drawing.Color.Black;<span class="comment">//将传送的颜色设置为透明，该方法设置的透明可以透过窗体使鼠标点击下方控件</span></span><br></pre></td></tr></table></figure>
<p>使用该方法“抹除”背景后，鼠标可直接操作原背景框下面的程序，除非有自身控件挡住，但该方法无法更改透明度，完全透明的背景会使字体边框有残痕，很不美观。</p>
<h4 id="取消挂载任务栏："><a href="#取消挂载任务栏：" class="headerlink" title="取消挂载任务栏："></a>取消挂载任务栏：</h4><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.ShowInTaskbar = <span class="literal">false</span>;<span class="comment">//不在任务栏显示```</span></span><br><span class="line">&lt;h4&gt;窗口置顶：&lt;/h4&gt;</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">this</span>.TopMost = <span class="literal">true</span>;<span class="comment">//窗口置顶```</span></span><br><span class="line">&lt;h4&gt;更改窗体透明度：&lt;/h4&gt;</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">this</span>.Opacity = <span class="number">0.5</span>D;<span class="comment">//传入double型变量```</span></span><br><span class="line"></span><br><span class="line">注意该方法更改窗体透明度后窗体内的空间透明度也会随之改变。</span><br><span class="line">&lt;h4&gt;更改窗口位置：&lt;/h4&gt;</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">this</span>.Location = <span class="keyword">new</span> Point(X,Y);<span class="comment">//不是变量、无法更改的窗口参量可以用new设置```</span></span><br><span class="line"></span><br><span class="line">(X,Y)是一个点，单独更改某一个参量也可以用<span class="keyword">this</span>.Location.Height和<span class="keyword">this</span>.Location.Weight。</span><br><span class="line">&lt;h4&gt;更改字体/大小：&lt;/h4&gt;</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">this</span>.Font = <span class="keyword">new</span> System.Drawing.Font(<span class="string">&quot;宋体&quot;</span>, <span class="number">15</span>);```</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">&lt;h4&gt;更改窗口状态：&lt;/h4&gt;</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">this</span>.Visible = <span class="literal">false</span>; <span class="comment">//隐藏</span></span><br><span class="line"><span class="keyword">this</span>.WindowState = FormWindowState.Minimized; <span class="comment">//最小化</span></span><br><span class="line"><span class="keyword">this</span>.WindowState = FormWindowState.Maximized; <span class="comment">//最大化</span></span><br><span class="line"><span class="keyword">this</span>.WindowState = FormWindowState.Normal; <span class="comment">//正常</span></span><br><span class="line">&lt;/code&gt;&lt;/pre&gt;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">&lt;h1&gt;控件类&lt;/h1&gt;</span><br><span class="line"></span><br><span class="line">&lt;h2&gt;①实体控件&lt;/h2&gt;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">&lt;h4&gt;label标签：&lt;/h4&gt;</span><br><span class="line"></span><br><span class="line">更改字体颜色：</span><br><span class="line"></span><br><span class="line">&lt;pre&gt;&lt;code <span class="keyword">class</span>=<span class="string">&quot;language-csharp line-numbers&quot;</span>&gt;<span class="keyword">this</span>.label1.ForeColor = Color.FromArgb(<span class="number">211</span>, <span class="number">210</span>, <span class="number">199</span>); <span class="comment">//柔和灰```</span></span><br><span class="line"></span><br><span class="line">&lt;strong&gt;trackbar轨迹条：&lt;/strong&gt;</span><br><span class="line"></span><br><span class="line">获取，更改当前值：trackbar1.Value</span><br><span class="line">&lt;h4&gt;&lt;strong&gt;combobox组合框：&lt;/strong&gt;&lt;/h4&gt;</span><br><span class="line">&lt;strong&gt;添加组合&lt;/strong&gt;：将鼠标移到组合框上单击，选择黑色箭头，选择编辑项&lt;img <span class="keyword">class</span>=<span class="string">&quot;alignnone size-full wp-image-433&quot;</span> src=<span class="string">&quot;http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-18_10-23-07.png&quot;</span> alt=<span class="string">&quot;&quot;</span> width=<span class="string">&quot;990&quot;</span> height=<span class="string">&quot;561&quot;</span> /&gt;</span><br><span class="line"></span><br><span class="line">&lt;strong&gt;选择组合&lt;/strong&gt;：添加选项后，编译器将自动生成目录（index），编程时，既可以根据选项值选择，也可以根据目录选择。</span><br><span class="line"></span><br><span class="line">根据选项值选择：</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">switch</span> (comboBox1.SelectedItem.ToString())<span class="comment">//按选项值选择</span></span><br><span class="line">&#123;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;深黑&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;纯白&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;柔和灰&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">211</span>, <span class="number">210</span>, <span class="number">199</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;荷兰白&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">226</span>, <span class="number">225</span>, <span class="number">185</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;日本靛蓝&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">42</span>, <span class="number">61</span>, <span class="number">69</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;深帝国蓝&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">5</span>, <span class="number">60</span>, <span class="number">94</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;简约蓝&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">31</span>, <span class="number">122</span>, <span class="number">140</span>); <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&quot;赭石色&quot;</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">211</span>, <span class="number">139</span>, <span class="number">93</span>); <span class="keyword">break</span>;</span><br><span class="line">&#125;```</span><br><span class="line"></span><br><span class="line">按目录选择：</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="keyword">switch</span> (comboBox1.SelectedIndex)<span class="comment">//按目录选择</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">0</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">1</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>);<span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">2</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">211</span>, <span class="number">210</span>, <span class="number">199</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">3</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">226</span>, <span class="number">225</span>, <span class="number">185</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">4</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">42</span>, <span class="number">61</span>, <span class="number">69</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">5</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">5</span>, <span class="number">60</span>, <span class="number">94</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">6</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">31</span>, <span class="number">122</span>, <span class="number">140</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">7</span>: clock1.label1.ForeColor = Color.FromArgb(<span class="number">211</span>, <span class="number">139</span>, <span class="number">93</span>); <span class="keyword">break</span>;</span><br><span class="line">&#125;```</span><br><span class="line">&lt;h2&gt;②虚拟控件&lt;/h2&gt;</span><br><span class="line">&lt;h4&gt;timer控件:&lt;/h4&gt;</span><br><span class="line">timer控件可以按时间触发事件，以毫秒为单位（<span class="number">1</span>s=<span class="number">1000</span>ms）</span><br><span class="line"></span><br><span class="line">&lt;strong&gt;建立：&lt;/strong&gt;使用时，将工具箱里的timer控件拖入窗体即可，在下方就可以找到该控件，右击属性可以设置间隔时间。</span><br><span class="line"></span><br><span class="line">&lt;strong&gt;触发：&lt;/strong&gt;在动作_Tick中可直接设置间隔时间到时出发的动作</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">timer1_Tick</span>(<span class="params"><span class="built_in">object</span> sender, EventArgs e</span>)<span class="comment">//设置更新时间，自动更新时间，传送静态值到label1.Text，绕过了不能直接传送动态值的问题</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    label1.Text = DateTime.Now.Hour + <span class="string">&quot;:&quot;</span> + DateTime.Now.Minute + <span class="string">&quot;:&quot;</span> + DateTime.Now.Second;<span class="comment">//更新目前时间到label1.Text</span></span><br><span class="line">&#125;```</span><br><span class="line"></span><br><span class="line">&lt;strong&gt;notifyIcon状态栏图标控件：&lt;/strong&gt;</span><br><span class="line"></span><br><span class="line">可以在状态栏创建应用图标，在单击时可出发动作。</span><br><span class="line"></span><br><span class="line">&lt;strong&gt;建立：&lt;/strong&gt;与timer一样直接拖入即可，但是notifyIcon一定要在属性中设置图标，否则不会再状态栏显示。</span><br><span class="line"></span><br><span class="line">&lt;strong&gt;触发：&lt;/strong&gt;可设置多种触发方式，如单击双击等，一般触发后代码为还原窗体大小+激活窗体</span><br><span class="line"></span><br><span class="line">```csharp</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">notifyIcon1_MouseClick</span>(<span class="params"><span class="built_in">object</span> sender, MouseEventArgs e</span>)<span class="comment">//点击状态栏的触发效果</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (WindowState == FormWindowState.Minimized)<span class="comment">//最小化时</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//还原窗体显示</span></span><br><span class="line">        WindowState = FormWindowState.Normal;</span><br><span class="line">        <span class="comment">//激活窗体并给予它焦点</span></span><br><span class="line">        <span class="keyword">this</span>.Activate();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="技巧"><a href="#技巧" class="headerlink" title="技巧"></a>技巧</h1><h2 id="①保存设置"><a href="#①保存设置" class="headerlink" title="①保存设置"></a>①保存设置</h2><p>对解决方案右键，添加，新建项，选择设置文件，对文件命名。 <img src="http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-19_12-26-35.png" alt=""> 调用设置：直接将“设置名.Default.变量名”赋给目标变量即可 存储设置：直接讲变量赋给“设置名.Default.变量名”，然后键入<strong>设置名.Default.Save();</strong>  </p>
<h2 id="②鼠标穿透"><a href="#②鼠标穿透" class="headerlink" title="②鼠标穿透"></a>②鼠标穿透</h2><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System.Runtime.InteropServices;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">const</span> uint WS_EX_LAYERED = <span class="number">0x80000</span>;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">const</span> <span class="built_in">int</span> WS_EX_TRANSPARENT = <span class="number">0x20</span>;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">const</span> <span class="built_in">int</span> GWL_STYLE = (<span class="number">-16</span>);</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">const</span> <span class="built_in">int</span> GWL_EXSTYLE = (<span class="number">-20</span>);</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">const</span> <span class="built_in">int</span> LWA_ALPHA = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">[<span class="meta">DllImport(<span class="meta-string">&quot;user32&quot;</span>, EntryPoint = <span class="meta-string">&quot;SetWindowLong&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">extern</span> uint <span class="title">SetWindowLong</span>(<span class="params"></span></span></span><br><span class="line"><span class="function"><span class="params">IntPtr hwnd,</span></span></span><br><span class="line"><span class="function"><span class="params"><span class="built_in">int</span> nIndex,</span></span></span><br><span class="line"><span class="function"><span class="params">uint dwNewLong</span></span></span><br><span class="line"><span class="function"><span class="params"></span>)</span>;</span><br><span class="line"></span><br><span class="line">[<span class="meta">DllImport(<span class="meta-string">&quot;user32&quot;</span>, EntryPoint = <span class="meta-string">&quot;GetWindowLong&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">extern</span> uint <span class="title">GetWindowLong</span>(<span class="params"></span></span></span><br><span class="line"><span class="function"><span class="params">IntPtr hwnd,</span></span></span><br><span class="line"><span class="function"><span class="params"><span class="built_in">int</span> nIndex</span></span></span><br><span class="line"><span class="function"><span class="params"></span>)</span>;</span><br><span class="line"></span><br><span class="line">[<span class="meta">DllImport(<span class="meta-string">&quot;user32&quot;</span>, EntryPoint = <span class="meta-string">&quot;SetLayeredWindowAttributes&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">extern</span> <span class="built_in">int</span> <span class="title">SetLayeredWindowAttributes</span>(<span class="params"></span></span></span><br><span class="line"><span class="function"><span class="params">IntPtr hwnd,</span></span></span><br><span class="line"><span class="function"><span class="params"><span class="built_in">int</span> crKey,</span></span></span><br><span class="line"><span class="function"><span class="params"><span class="built_in">int</span> bAlpha,</span></span></span><br><span class="line"><span class="function"><span class="params"><span class="built_in">int</span> dwFlags</span></span></span><br><span class="line"><span class="function"><span class="params"></span>)</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 设置窗体具有鼠标穿透效果</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">SetPenetrate</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">GetWindowLong(<span class="keyword">this</span>.Handle, GWL_EXSTYLE);</span><br><span class="line">SetWindowLong(<span class="keyword">this</span>.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT  WS_EX_LAYERED);</span><br><span class="line">SetLayeredWindowAttributes(<span class="keyword">this</span>.Handle, <span class="number">0</span>, <span class="number">100</span>, LWA_ALPHA);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//以上是鼠标穿透的代码，原代码来自网址：https://bbs.csdn.net/topics/390325341</span></span><br></pre></td></tr></table></figure>
    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/08/17/proj_miniclock/" rel="prev" title="【C#】Mini clock小时钟">
      <i class="fa fa-chevron-left"></i> 【C#】Mini clock小时钟
    </a></div>
      <div class="post-nav-item">
    <a href="/2018/08/19/proj_anypin/" rel="next" title="AnyPin开发计划">
      AnyPin开发计划 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%AA%97%E5%8F%A3%E7%B1%BB"><span class="nav-number">1.</span> <span class="nav-text">窗口类</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E2%91%A0%E5%88%9B%E5%BB%BA%E5%92%8C%E6%8E%A7%E5%88%B6%E5%A4%9A%E7%AA%97%E5%8F%A3"><span class="nav-number">1.1.</span> <span class="nav-text">①创建和控制多窗口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E2%91%A1%E6%9B%B4%E6%94%B9%E7%AA%97%E5%8F%A3%E5%8F%82%E9%87%8F"><span class="nav-number">1.2.</span> <span class="nav-text">②更改窗口参量</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E2%80%9C%E6%8A%B9%E9%99%A4%E2%80%9D%E7%AA%97%E5%8F%A3%E8%83%8C%E6%99%AF%EF%BC%9A"><span class="nav-number">1.2.0.1.</span> <span class="nav-text">“抹除”窗口背景：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%96%E6%B6%88%E6%8C%82%E8%BD%BD%E4%BB%BB%E5%8A%A1%E6%A0%8F%EF%BC%9A"><span class="nav-number">1.2.0.2.</span> <span class="nav-text">取消挂载任务栏：</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%8A%80%E5%B7%A7"><span class="nav-number">2.</span> <span class="nav-text">技巧</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E2%91%A0%E4%BF%9D%E5%AD%98%E8%AE%BE%E7%BD%AE"><span class="nav-number">2.1.</span> <span class="nav-text">①保存设置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E2%91%A1%E9%BC%A0%E6%A0%87%E7%A9%BF%E9%80%8F"><span class="nav-number">2.2.</span> <span class="nav-text">②鼠标穿透</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Tim"
      src="/uploads/avatar.png">
  <p class="site-author-name" itemprop="name">Tim</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">90</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">40</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yimig" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yimig" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:zhangyiming@programmer.net" title="E-Mail → mailto:zhangyiming@programmer.net" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://leetcode.com/yimig/" title="LeeCode → https:&#x2F;&#x2F;leetcode.com&#x2F;yimig&#x2F;" rel="noopener" target="_blank"><i class="fa fa-fw fa-code"></i>LeeCode</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.zhihu.com/people/tim-2-96" title="zhihu → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;tim-2-96" rel="noopener" target="_blank"><i class="fa fa-fw fa-question-circle"></i>zhihu</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://upane.cn/" title="https:&#x2F;&#x2F;upane.cn" rel="noopener" target="_blank">博客旧址</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tim</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">183k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:46</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/three.min.js"></script>
    <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/canvas_sphere.min.js"></script>


  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/js/local-search.js"></script>













  

  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : 'a876807f33858291f9d9',
      clientSecret: '7a5c6a83611c309965d7339d7ca5f16e34a21e9f',
      repo        : 'yimig.github.io',
      owner       : 'yimig',
      admin       : ['yimig'],
      id          : 'ecfd1f6993ca5bb1f17ef932c70026fd',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

</body>
</html>
